<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libcai: lib/cai.h 文件参考</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">libcai
   </div>
   <div id="projectbrief">大模型在线推理C语言函数库</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'搜索','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_97aefd0d527b934f1d99a682da8fe6a9.html">lib</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#typedef-members">类型定义</a> &#124;
<a href="#func-members">函数</a>  </div>
  <div class="headertitle">
<div class="title">cai.h 文件参考</div>  </div>
</div><!--header-->
<div class="contents">

<p><a href="cai_8h_source.html">浏览源代码.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="typedef-members"></a>
类型定义</h2></td></tr>
<tr class="memitem:aa0345f8fbe1dcd7b536c6f7457702777"><td class="memItemLeft" align="right" valign="top">typedef void(*&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="cai_8h.html#aa0345f8fbe1dcd7b536c6f7457702777">cai_stream_callback</a>) (void *userdata, char *content, char *reason)</td></tr>
<tr class="memdesc:aa0345f8fbe1dcd7b536c6f7457702777"><td class="mdescLeft">&#160;</td><td class="mdescRight">流式响应回调函数原型  <a href="cai_8h.html#aa0345f8fbe1dcd7b536c6f7457702777">更多...</a><br /></td></tr>
<tr class="separator:aa0345f8fbe1dcd7b536c6f7457702777"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
函数</h2></td></tr>
<tr class="memitem:afcda987a680fdb35bc441cdd42ffa874"><td class="memItemLeft" align="right" valign="top">struct cai_convo *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="cai_8h.html#afcda987a680fdb35bc441cdd42ffa874">cai_convo_create</a> (const char *prompt, int max)</td></tr>
<tr class="memdesc:afcda987a680fdb35bc441cdd42ffa874"><td class="mdescLeft">&#160;</td><td class="mdescRight">新建对话  <a href="cai_8h.html#afcda987a680fdb35bc441cdd42ffa874">更多...</a><br /></td></tr>
<tr class="separator:afcda987a680fdb35bc441cdd42ffa874"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a94ca6ff9ef763a7171eba6ae4a49b363"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="cai_8h.html#a94ca6ff9ef763a7171eba6ae4a49b363">cai_convo_destroy</a> (struct cai_convo *convo)</td></tr>
<tr class="memdesc:a94ca6ff9ef763a7171eba6ae4a49b363"><td class="mdescLeft">&#160;</td><td class="mdescRight">删除对话  <a href="cai_8h.html#a94ca6ff9ef763a7171eba6ae4a49b363">更多...</a><br /></td></tr>
<tr class="separator:a94ca6ff9ef763a7171eba6ae4a49b363"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3c75f1ff8b6f71383638e418a660a980"><td class="memItemLeft" align="right" valign="top">struct cai_convo *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="cai_8h.html#a3c75f1ff8b6f71383638e418a660a980">cai_convo_load</a> (const char *file)</td></tr>
<tr class="memdesc:a3c75f1ff8b6f71383638e418a660a980"><td class="mdescLeft">&#160;</td><td class="mdescRight">从文件中加载对话上下文  <a href="cai_8h.html#a3c75f1ff8b6f71383638e418a660a980">更多...</a><br /></td></tr>
<tr class="separator:a3c75f1ff8b6f71383638e418a660a980"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2efe9210138bbc4caca08370faf3e0e0"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="cai_8h.html#a2efe9210138bbc4caca08370faf3e0e0">cai_convo_save</a> (struct cai_convo *convo, const char *file)</td></tr>
<tr class="memdesc:a2efe9210138bbc4caca08370faf3e0e0"><td class="mdescLeft">&#160;</td><td class="mdescRight">将对话上下文保存到文件中  <a href="cai_8h.html#a2efe9210138bbc4caca08370faf3e0e0">更多...</a><br /></td></tr>
<tr class="separator:a2efe9210138bbc4caca08370faf3e0e0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3e13b5d6ba406a91e31885de87ff329b"><td class="memItemLeft" align="right" valign="top">struct cai_asst *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="cai_8h.html#a3e13b5d6ba406a91e31885de87ff329b">cai_asst_create</a> (const char *api_key, const char *base_url, const char *model)</td></tr>
<tr class="memdesc:a3e13b5d6ba406a91e31885de87ff329b"><td class="mdescLeft">&#160;</td><td class="mdescRight">创建AI助手  <a href="cai_8h.html#a3e13b5d6ba406a91e31885de87ff329b">更多...</a><br /></td></tr>
<tr class="separator:a3e13b5d6ba406a91e31885de87ff329b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3a8fccff87a9ceb0f2b9d88988794372"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="cai_8h.html#a3a8fccff87a9ceb0f2b9d88988794372">cai_asst_destroy</a> (struct cai_asst *asst)</td></tr>
<tr class="memdesc:a3a8fccff87a9ceb0f2b9d88988794372"><td class="mdescLeft">&#160;</td><td class="mdescRight">删除AI助手  <a href="cai_8h.html#a3a8fccff87a9ceb0f2b9d88988794372">更多...</a><br /></td></tr>
<tr class="separator:a3a8fccff87a9ceb0f2b9d88988794372"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a85b6aeb892a8e4725274ea2b8cde2c60"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="cai_8h.html#a85b6aeb892a8e4725274ea2b8cde2c60">cai_set_stream_callback</a> (struct cai_asst *asst, <a class="el" href="cai_8h.html#aa0345f8fbe1dcd7b536c6f7457702777">cai_stream_callback</a> callback, void *userdata)</td></tr>
<tr class="memdesc:a85b6aeb892a8e4725274ea2b8cde2c60"><td class="mdescLeft">&#160;</td><td class="mdescRight">设置流式响应回调函数  <a href="cai_8h.html#a85b6aeb892a8e4725274ea2b8cde2c60">更多...</a><br /></td></tr>
<tr class="separator:a85b6aeb892a8e4725274ea2b8cde2c60"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a38fc36d328aefa41f86c335961483235"><td class="memItemLeft" align="right" valign="top">char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="cai_8h.html#a38fc36d328aefa41f86c335961483235">cai_asst_chat</a> (struct cai_asst *asst, struct cai_convo *conv, const char *question, const char *file)</td></tr>
<tr class="memdesc:a38fc36d328aefa41f86c335961483235"><td class="mdescLeft">&#160;</td><td class="mdescRight">与AI助手对话  <a href="cai_8h.html#a38fc36d328aefa41f86c335961483235">更多...</a><br /></td></tr>
<tr class="separator:a38fc36d328aefa41f86c335961483235"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">类型定义说明</h2>
<a id="aa0345f8fbe1dcd7b536c6f7457702777"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa0345f8fbe1dcd7b536c6f7457702777">&#9670;&nbsp;</a></span>cai_stream_callback</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">typedef void(* cai_stream_callback) (void *userdata, char *content, char *reason)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>流式响应回调函数原型 </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">content</td><td>接收到的内容片段 </td></tr>
    <tr><td class="paramname">reason</td><td>收到的推理内容 </td></tr>
    <tr><td class="paramname">userdata</td><td>用户自定义数据指针 </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<h2 class="groupheader">函数说明</h2>
<a id="a38fc36d328aefa41f86c335961483235"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a38fc36d328aefa41f86c335961483235">&#9670;&nbsp;</a></span>cai_asst_chat()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">char* cai_asst_chat </td>
          <td>(</td>
          <td class="paramtype">struct cai_asst *&#160;</td>
          <td class="paramname"><em>asst</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">struct cai_convo *&#160;</td>
          <td class="paramname"><em>conv</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>question</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>file</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>与AI助手对话 </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">asst</td><td>AI助手结构体地址 </td></tr>
    <tr><td class="paramname">conv</td><td>对话结构体地址，如果为NULL，则不保存对话上下文 </td></tr>
    <tr><td class="paramname">question</td><td>用户的问题 </td></tr>
    <tr><td class="paramname">file</td><td>输入的文件，用于支持多模态的大模型，可以为NULL </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>返回</dt><dd>char* 返回AI助手的回答，会自动释放 </dd></dl>

</div>
</div>
<a id="a3e13b5d6ba406a91e31885de87ff329b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3e13b5d6ba406a91e31885de87ff329b">&#9670;&nbsp;</a></span>cai_asst_create()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">struct cai_asst* cai_asst_create </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>api_key</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>base_url</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>model</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>创建AI助手 </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">api_key</td><td>API认证密钥 </td></tr>
    <tr><td class="paramname">base_url</td><td>API服务地址 </td></tr>
    <tr><td class="paramname">model</td><td>模型名称 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>返回</dt><dd>struct cai_asst* 成功返回AI助手结构体地址，失败返回NULL </dd></dl>

</div>
</div>
<a id="a3a8fccff87a9ceb0f2b9d88988794372"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3a8fccff87a9ceb0f2b9d88988794372">&#9670;&nbsp;</a></span>cai_asst_destroy()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cai_asst_destroy </td>
          <td>(</td>
          <td class="paramtype">struct cai_asst *&#160;</td>
          <td class="paramname"><em>asst</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>删除AI助手 </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">asst</td><td>AI助手结构体地址 </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="afcda987a680fdb35bc441cdd42ffa874"></a>
<h2 class="memtitle"><span class="permalink"><a href="#afcda987a680fdb35bc441cdd42ffa874">&#9670;&nbsp;</a></span>cai_convo_create()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">struct cai_convo* cai_convo_create </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>prompt</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>max</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>新建对话 </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">prompt</td><td>系统提示词，NULL为不使用 </td></tr>
    <tr><td class="paramname">max</td><td>对话保存的最多消息数，0为不限制 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>返回</dt><dd>struct cai_convo* 成功返回对话结构体地址，失败返回NULL </dd></dl>

</div>
</div>
<a id="a94ca6ff9ef763a7171eba6ae4a49b363"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a94ca6ff9ef763a7171eba6ae4a49b363">&#9670;&nbsp;</a></span>cai_convo_destroy()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cai_convo_destroy </td>
          <td>(</td>
          <td class="paramtype">struct cai_convo *&#160;</td>
          <td class="paramname"><em>convo</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>删除对话 </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">convo</td><td>对话结构体地址 </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a3c75f1ff8b6f71383638e418a660a980"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3c75f1ff8b6f71383638e418a660a980">&#9670;&nbsp;</a></span>cai_convo_load()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">struct cai_convo* cai_convo_load </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>file</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>从文件中加载对话上下文 </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">file</td><td>保存对话上下文的文件路径 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>返回</dt><dd>struct cai_convo* 成功返回对话结构体地址，失败返回NULL </dd></dl>

</div>
</div>
<a id="a2efe9210138bbc4caca08370faf3e0e0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2efe9210138bbc4caca08370faf3e0e0">&#9670;&nbsp;</a></span>cai_convo_save()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int cai_convo_save </td>
          <td>(</td>
          <td class="paramtype">struct cai_convo *&#160;</td>
          <td class="paramname"><em>convo</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>file</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>将对话上下文保存到文件中 </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">convo</td><td>对话结构体地址 </td></tr>
    <tr><td class="paramname">file</td><td>保存对话上下文的文件路径 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>返回</dt><dd>int 成功返回0，失败返回-1 </dd></dl>

</div>
</div>
<a id="a85b6aeb892a8e4725274ea2b8cde2c60"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a85b6aeb892a8e4725274ea2b8cde2c60">&#9670;&nbsp;</a></span>cai_set_stream_callback()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cai_set_stream_callback </td>
          <td>(</td>
          <td class="paramtype">struct cai_asst *&#160;</td>
          <td class="paramname"><em>asst</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="cai_8h.html#aa0345f8fbe1dcd7b536c6f7457702777">cai_stream_callback</a>&#160;</td>
          <td class="paramname"><em>callback</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>userdata</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>设置流式响应回调函数 </p>
<dl class="params"><dt>参数</dt><dd>
  <table class="params">
    <tr><td class="paramname">asst</td><td>AI助手结构体地址 </td></tr>
    <tr><td class="paramname">callback</td><td>回调函数 </td></tr>
    <tr><td class="paramname">userdata</td><td>用户自定义数据指针 </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>
